package m4d1;

import java.io.*;
import java.net.Socket;

//文件上传客户端
public class eTCPClient2 {
    public static void main(String[] args) throws IOException {
        //本地字节输入流绑定要上传的数据员
        FileInputStream fis = new FileInputStream("day02\\src\\m4d1\\b.txt");

        //客户端绑定服务器ip端口
        Socket socket = new Socket("127.0.0.1",1234);

        //获取网络字节流对象
        OutputStream os = socket.getOutputStream();

        //本地字节流读取本地文件
        int len = 0;
        byte[] bytes = new byte[1025];
        while((len = fis.read(bytes))!=-1){
            //网络字节输出流传文件到服务器
            os.write(bytes,0,len);
        }

        //上传完文件后，给服务器结束标记
        socket.shutdownOutput();

        //获取网络字节输入流对象
        InputStream is = socket.getInputStream();

        //读取服务器回写的数据
        while((len = is.read(bytes))!=-1){
            System.out.println(new String(bytes,0,len));
        }

        fis.close();
        socket.close();
    }
}
